package com.prelearning.at_springboot.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.prelearning.at_springboot.service.IChatInfoService;
import com.prelearning.at_springboot.entity.ChatInfo;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cgr
 * @since 2022-04-28
 */
@RestController
@RequestMapping("/chatInfo")
public class ChatInfoController {

    @Resource
    private IChatInfoService chatInfoService;

    // 新增或更新
    @PostMapping
    public boolean save(@RequestBody ChatInfo chatInfo) {
            return chatInfoService.saveOrUpdate(chatInfo);
    }

    //根据id删除
    @DeleteMapping("/{id}")
    public Boolean delete(@PathVariable String id) {
            return chatInfoService.removeById(id);
    }

    //多项删除
    @PostMapping("/del/batch")
    public boolean deleteBatch(@RequestBody List<String> ids) {
            return chatInfoService.removeByIds(ids);
    }

    //获取所有数据
    @GetMapping
    public List<ChatInfo> findAll() {
            return chatInfoService.list();
    }

    //根据id获取数据
    @GetMapping("/{id}")
    public ChatInfo findOne(@PathVariable String id) {
            return chatInfoService.getById(id);
    }

    //根据用户id获取所管理的群组信息
    @GetMapping("/chats/{owner_id}")
    public List<ChatInfo> findByOwner(@PathVariable String owner_id){ return chatInfoService.getByOwner(owner_id); }


}

